<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="身份证号" prop="identityId">
        <el-input
          v-model="queryParams.identityId"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生日">
        <el-date-picker
          v-model="daterangeBirthday"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="民族" prop="race">
        <el-input
          v-model="queryParams.race"
          placeholder="请输入民族"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="政治面貌" prop="party">
        <el-input
          v-model="queryParams.party"
          placeholder="请输入政治面貌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文化程度" prop="degree">
        <el-input
          v-model="queryParams.degree"
          placeholder="请输入文化程度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="major">
        <el-input
          v-model="queryParams.major"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业学校" prop="graduateFrom">
        <el-input
          v-model="queryParams.graduateFrom"
          placeholder="请输入毕业学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业日期" prop="graduateDate">
        <el-input
          v-model="queryParams.graduateDate"
          placeholder="请输入毕业日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参加工作日期">
        <el-date-picker
          v-model="daterangeEmployDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="职工类别" prop="category">
        <el-input
          v-model="queryParams.category"
          placeholder="请输入职工类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="站段" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入站段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门" prop="department">
        <el-input
          v-model="queryParams.department"
          placeholder="请输入部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班组" prop="workGroup">
        <el-input
          v-model="queryParams.workGroup"
          placeholder="请输入班组"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任职日期">
        <el-date-picker
          v-model="daterangePromoteDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="职称" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入职称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职业资格" prop="Qualification">
        <el-input
          v-model="queryParams.Qualification"
          placeholder="请输入职业资格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职业资格等级" prop="QualificationGrade">
        <el-input
          v-model="queryParams.QualificationGrade"
          placeholder="请输入职业资格等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工种" prop="skill">
        <el-input
          v-model="queryParams.skill"
          placeholder="请输入工种"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工种等级" prop="skillGrade">
        <el-input
          v-model="queryParams.skillGrade"
          placeholder="请输入工种等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班组长" prop="monitor">
        <el-input
          v-model="queryParams.monitor"
          placeholder="请输入班组长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="百千万人才" prop="elitist">
        <el-input
          v-model="queryParams.elitist"
          placeholder="请输入百千万人才"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特种设备操作" prop="specialEquipment">
        <el-input
          v-model="queryParams.specialEquipment"
          placeholder="请输入特种设备操作"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特殊工种" prop="specialSkill">
        <el-input
          v-model="queryParams.specialSkill"
          placeholder="请输入特殊工种"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业线施工" prop="supervisor">
        <el-input
          v-model="queryParams.supervisor"
          placeholder="请输入营业线施工"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技能称号" prop="honor">
        <el-input
          v-model="queryParams.honor"
          placeholder="请输入技能称号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="note">
        <el-input
          v-model="queryParams.note"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:employee:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:employee:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:employee:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:employee:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工资号
" align="center" prop="employeeId" />
      <el-table-column label="身份证号" align="center" prop="identityId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="生日" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="民族" align="center" prop="race" />
      <el-table-column label="政治面貌" align="center" prop="party" />
      <el-table-column label="文化程度" align="center" prop="degree" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="毕业学校" align="center" prop="graduateFrom" />
      <el-table-column label="毕业日期" align="center" prop="graduateDate" />
      <el-table-column label="参加工作日期" align="center" prop="employDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.employDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职工类别" align="center" prop="category" />
      <el-table-column label="站段" align="center" prop="company" />
      <el-table-column label="部门" align="center" prop="department" />
      <el-table-column label="班组" align="center" prop="workGroup" />
      <el-table-column label="职务" align="center" prop="position" />
      <el-table-column label="任职日期" align="center" prop="promoteDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.promoteDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职称" align="center" prop="title" />
      <el-table-column label="职业资格" align="center" prop="Qualification" />
      <el-table-column label="职业资格等级" align="center" prop="QualificationGrade" />
      <el-table-column label="工种" align="center" prop="skill" />
      <el-table-column label="工种等级" align="center" prop="skillGrade" />
      <el-table-column label="班组长" align="center" prop="monitor" />
      <el-table-column label="百千万人才" align="center" prop="elitist" />
      <el-table-column label="特种设备操作" align="center" prop="specialEquipment" />
      <el-table-column label="特殊工种" align="center" prop="specialSkill" />
      <el-table-column label="营业线施工" align="center" prop="supervisor" />
      <el-table-column label="技能称号" align="center" prop="honor" />
      <el-table-column label="状态" align="center" prop="state" />
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:employee:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:employee:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改职工基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="身份证号" prop="identityId">
          <el-input v-model="form.identityId" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-date-picker clearable
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="民族" prop="race">
          <el-input v-model="form.race" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="party">
          <el-input v-model="form.party" placeholder="请输入政治面貌" />
        </el-form-item>
        <el-form-item label="文化程度" prop="degree">
          <el-input v-model="form.degree" placeholder="请输入文化程度" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="毕业学校" prop="graduateFrom">
          <el-input v-model="form.graduateFrom" placeholder="请输入毕业学校" />
        </el-form-item>
        <el-form-item label="毕业日期" prop="graduateDate">
          <el-input v-model="form.graduateDate" placeholder="请输入毕业日期" />
        </el-form-item>
        <el-form-item label="参加工作日期" prop="employDate">
          <el-date-picker clearable
            v-model="form.employDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择参加工作日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="职工类别" prop="category">
          <el-input v-model="form.category" placeholder="请输入职工类别" />
        </el-form-item>
        <el-form-item label="站段" prop="company">
          <el-input v-model="form.company" placeholder="请输入站段" />
        </el-form-item>
        <el-form-item label="部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="班组" prop="workGroup">
          <el-input v-model="form.workGroup" placeholder="请输入班组" />
        </el-form-item>
        <el-form-item label="职务" prop="position">
          <el-input v-model="form.position" placeholder="请输入职务" />
        </el-form-item>
        <el-form-item label="任职日期" prop="promoteDate">
          <el-date-picker clearable
            v-model="form.promoteDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择任职日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="职称" prop="title">
          <el-input v-model="form.title" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="职业资格" prop="Qualification">
          <el-input v-model="form.Qualification" placeholder="请输入职业资格" />
        </el-form-item>
        <el-form-item label="职业资格等级" prop="QualificationGrade">
          <el-input v-model="form.QualificationGrade" placeholder="请输入职业资格等级" />
        </el-form-item>
        <el-form-item label="工种" prop="skill">
          <el-input v-model="form.skill" placeholder="请输入工种" />
        </el-form-item>
        <el-form-item label="工种等级" prop="skillGrade">
          <el-input v-model="form.skillGrade" placeholder="请输入工种等级" />
        </el-form-item>
        <el-form-item label="班组长" prop="monitor">
          <el-input v-model="form.monitor" placeholder="请输入班组长" />
        </el-form-item>
        <el-form-item label="百千万人才" prop="elitist">
          <el-input v-model="form.elitist" placeholder="请输入百千万人才" />
        </el-form-item>
        <el-form-item label="特种设备操作" prop="specialEquipment">
          <el-input v-model="form.specialEquipment" placeholder="请输入特种设备操作" />
        </el-form-item>
        <el-form-item label="特殊工种" prop="specialSkill">
          <el-input v-model="form.specialSkill" placeholder="请输入特殊工种" />
        </el-form-item>
        <el-form-item label="营业线施工" prop="supervisor">
          <el-input v-model="form.supervisor" placeholder="请输入营业线施工" />
        </el-form-item>
        <el-form-item label="技能称号" prop="honor">
          <el-input v-model="form.honor" placeholder="请输入技能称号" />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="虚拟删除" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入虚拟删除" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmployee, getEmployee, delEmployee, addEmployee, updateEmployee } from "@/api/talent-management/employee";

export default {
  name: "Employee",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 职工基本信息表格数据
      employeeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 虚拟删除时间范围
      daterangeBirthday: [],
      // 虚拟删除时间范围
      daterangeEmployDate: [],
      // 虚拟删除时间范围
      daterangePromoteDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        identityId: null,
        name: null,
        gender: null,
        birthday: null,
        phone: null,
        race: null,
        party: null,
        degree: null,
        major: null,
        graduateFrom: null,
        graduateDate: null,
        employDate: null,
        category: null,
        company: null,
        department: null,
        workGroup: null,
        position: null,
        promoteDate: null,
        title: null,
        Qualification: null,
        QualificationGrade: null,
        skill: null,
        skillGrade: null,
        monitor: null,
        elitist: null,
        specialEquipment: null,
        specialSkill: null,
        supervisor: null,
        honor: null,
        state: null,
        note: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询职工基本信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeBirthday && '' != this.daterangeBirthday) {
        this.queryParams.params["beginBirthday"] = this.daterangeBirthday[0];
        this.queryParams.params["endBirthday"] = this.daterangeBirthday[1];
      }
      if (null != this.daterangeEmployDate && '' != this.daterangeEmployDate) {
        this.queryParams.params["beginEmployDate"] = this.daterangeEmployDate[0];
        this.queryParams.params["endEmployDate"] = this.daterangeEmployDate[1];
      }
      if (null != this.daterangePromoteDate && '' != this.daterangePromoteDate) {
        this.queryParams.params["beginPromoteDate"] = this.daterangePromoteDate[0];
        this.queryParams.params["endPromoteDate"] = this.daterangePromoteDate[1];
      }
      listEmployee(this.queryParams).then(response => {
        this.employeeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        employeeId: null,
        identityId: null,
        name: null,
        gender: null,
        birthday: null,
        phone: null,
        race: null,
        party: null,
        degree: null,
        major: null,
        graduateFrom: null,
        graduateDate: null,
        employDate: null,
        category: null,
        company: null,
        department: null,
        workGroup: null,
        position: null,
        promoteDate: null,
        title: null,
        Qualification: null,
        QualificationGrade: null,
        skill: null,
        skillGrade: null,
        monitor: null,
        elitist: null,
        specialEquipment: null,
        specialSkill: null,
        supervisor: null,
        honor: null,
        state: null,
        note: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeBirthday = [];
      this.daterangeEmployDate = [];
      this.daterangePromoteDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.employeeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加职工基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const employeeId = row.employeeId || this.ids
      getEmployee(employeeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改职工基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.employeeId != null) {
            updateEmployee(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEmployee(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const employeeIds = row.employeeId || this.ids;
      this.$modal.confirm('是否确认删除职工基本信息编号为"' + employeeIds + '"的数据项？').then(function() {
        return delEmployee(employeeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/employee/export', {
        ...this.queryParams
      }, `employee_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
